mui.init();
var em = null,
	map = null,
	seats = [];
// H5 plus事件处理
function plusReady() {
	// 确保DOM解析完成
	if (!em || !window.plus || map) {
		return
	};
	map = new plus.maps.Map("map");

	/*var arr = [{
		"longitude": 116.215085,
		"latitude": 39.900964,
		id: 1
	}, {
		"longitude": 120.215085,
		"latitude": 39.900964,
		id: 2
	}, {
		"longitude": 116.215085,
		"latitude": 30.900964,
		id: 3
	}];*/

	//加载商场信息
	mui.ajax({
		url: getUrl('69find'),
		type: "post",
		dataType: 'json',
		timeout: 10000,
		success: function(data) {
			var markets = data.markets;
			for (var index in markets) {
				//markets[index].id = index;
				var shop = markets[index];
				seats[index] = {};
				seats[index].id = index;
				seats[index].mid = shop.mid;
				seats[index].longitude = shop.lon;
				seats[index].latitude = shop.lat;
				seats[index].name = shop.name;
				creatMaker(seats[index]);
				//seats.push(markets[index]);
			}
		},
		error: function(xhr, type, errorThrown) {}
	});
	/*for (var i = 0; i < arr.length; i++) {
		creatMaker(arr[i]);
	}*/
	console.log("地图加载完毕");
	showUser();

}
if (window.plus) {
	plusReady();
} else {
	document.addEventListener("plusready", plusReady, false);
}
// DOMContentloaded事件处理
document.addEventListener("DOMContentLoaded", function() {
	em = document.getElementById("map");
	var wscreenheight = document.documentElement.clientHeight - 94;
	em.style.height = wscreenheight + "px";
	plusReady();
}, false);
//获得用户位置信息
function getUserLocation() {
	map.getUserLocation(function(state, point) {
		if (0 == state) {
			setCenter(point);
		}
	})
}
//显示用户位置
function showUser() {
	map.showUserLocation(true);
	getUserLocation();
	map.isShowUserLocation();
}
//设置地图中心点
function setCenter(center) {
	setTimeout(function() {
		map.centerAndZoom(center, 12);
	}, 200)
}
//添加标注物
function creatMaker(point) {
	var imakId;
	var id = point.id;
	var marker = new plus.maps.Marker(point);
	marker.setIcon("../image/xq_dz.png");
	marker.setLabel(id + "");
	var bubble = new plus.maps.Bubble(point.name);
	bubble.setIcon("../image/my/ck_qz.png");
	marker.setBubble(bubble);
	map.addOverlay(marker);
	marker.onclick = function(marker) {
		imakId = marker.getLabel();
		for (var i in seats) {
			if (imakId == seats[i].id) {
				setCenter({
					"longitude": seats[i].longitude,
					"latitude": seats[i].longitude,
				});
			}
		}
	}
	bubble.onclick = function(bubble) {
		for (var i in seats) {
			if (imakId == seats[i].id) {
				//alert(seats[i].mid);
				localStorage.marketId=writeData(seats[i].mid);
				OpenNewWin({
					id:'market.html',
					url:'shopping/market.html'
				})
			}
		}
	}
}
//初始化数据
var find = new Vue({
		el: "#find",
		data: {
			arrlist: {}
		},
		ready: function() {
			//加载广告
			var adUrl = getUrl("75getAdvert");
			paramsAd = {
				advertLevel: "system"
			}
			mui.ajax({
				type: 'POST',
				url: adUrl,
				timeout: 10000,
				data: paramsAd,
				success: function(data) {
					var arrlist = {},
						index = 0;
					if (data.textList) {
						var toptextlist = data.textList.mids;
						for (var i = 0; i < toptextlist.length; i++) {
							if (i % 2 == 0) {
								arrlist[index] = [];
								arrlist[index].push(toptextlist[i]);
							} else {
								arrlist[index].push(toptextlist[i]);
								index++;
							}
						}
					}
					find.arrlist = arrlist;
				}
			})
		}
	})
	//扫描
function openscan() {
	OpenNewWin({
		url: "scan.html",
		id: "scan.html",
		Sanishow: "slide-in-bottom"
	})
}

function opensearch() {
	OpenNewWin({
		url: "shopping/search.html",
		id: "search.html"
	})
}
var mySwipertext = new Swiper(' .swiper-container', {
	direction: 'vertical',
	loop: true,
	autoplay: 5000,
	noSwiping: true,
	speed: 1000
});